<?php
namespace app\command;

use app\beautiful\model\order\BuyOrderModel;
use app\common\model\DataRecordModel;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class Memberlock_buyorder extends Command
{
    protected function configure()
    {
        $this->setName('Memberlock_buyorder')
            ->addArgument('name', Argument::OPTIONAL, "your name")
            ->addOption('city', null, Option::VALUE_REQUIRED, 'city name')
            ->setDescription('Say Hello');
    }

    protected function execute(Input $input, Output $output)
    {
        $datarecord= new DataRecordModel();
        $record_id=6;
        $record=$datarecord->where(['id'=>$record_id])->find();
        $old_edittime=empty($record)?'':$record['old_edittime'];
        $old_edittime=strtotime($old_edittime);
        $page=1;
        $num=10;
        $order['a.edit_time']='asc';
        $order['a.buy_order_id']='asc';
        do{
            $s=[];
            $s['edit_time']=$old_edittime;
            $s['is_paid']=1;
            $s['status']=1;
            $list=BuyOrderModel::list($s,$order,$page,$num);
            if(empty($list)){
                $output->writeln("暂无数据".var_export([$s,$order,$page],true) );exit();
            }
            foreach ($list as $v){
                memberlock($v['buy_order_id'],2);//锁客分红
            }
            $end=end($list);
            if(strtotime($end['edit_time'])==$old_edittime){
                $page++;
            }else{
                $old_edittime=strtotime($end['edit_time']);
                $up=[];
                $up['old_edittime']=date('Y-m-d H:i:s',$old_edittime);
                DataRecordModel::up($up,['id'=>$record_id]);
            }
        }while(true);
    }
}